

//
//  BlockViewController.m
//  Swift 3.0 基础语法
//
//  Created by YYY on 2017/7/18.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

#import "BlockViewController.h"

@interface BlockViewController ()

@property(nonatomic,copy)void (^completionBlock)();

@end

@implementation BlockViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //定义block
  
//    void (^myBlock)() = ^{
//        NSLog(@"this is block");
//    };
//    myBlock();
//    
    //解除引用1  __weak
    __weak typeof(self) weakSelf = self;
    [self loadData:^{
        NSLog(@"%@",weakSelf.view);
    }];
    // Do any additional setup after loading the view.
}


-(void)loadData:(void(^)())completion
{
    self.completionBlock = completion;
    
    
    
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSLog(@"耗时操作 %@",[NSThread currentThread]);
       
        dispatch_async(dispatch_get_main_queue(), ^{
            //执行操作
            completion();
        });
    });
}

-(void)dealloc
{
    NSLog(@"结束");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
